package org.apache.rocketmq.example.mysimple;

import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class quequeDemo {
    public static void main(String[] args) throws MQClientException {
        DefaultLitePullConsumer litePullConsumer = new DefaultLitePullConsumer("TopicTest");
        litePullConsumer.setNamesrvAddr("localhost:9876");
        litePullConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//        litePullConsumer.setAutoCommit(true);
        litePullConsumer.start();
        Collection<MessageQueue> messageQueues = litePullConsumer.fetchMessageQueues("TopicTest");
        ArrayList<MessageQueue> queues = new ArrayList<>(messageQueues);
        messageQueues.forEach(System.out::println);
        litePullConsumer.assign(queues);
        litePullConsumer.seek(queues.get(2),0);
        while(true){
            List<MessageExt> poll = litePullConsumer.poll();
            poll.forEach(System.out::println);
            litePullConsumer.commitSync();
        }
    }
}
